$(document).ready(function() {
	$.getJSON('./utilities/children_model.php', {
		operation : 'get_checkedin'
	}, function(data) {
		checked_in = data;
		for(var i = 0; i < checked_in.length; i++) {
			ci = checked_in[i];
			var new_logcard;
			new_logcard = new LogCard(ci['name'], '.' + ci['picture']);
			$("#id-wrapper").prepend(new_logcard.getDiv());
			new_logcard.createSliders();
		}
	});

	$("#btnSubmit").click(function() {
		$("#btnSubmit").attr("disabled", "true");
		$(".slider").slider({
			disabled : true
		});
		$("textarea").attr("disabled", true);
		
		$.getJSON('./utilities/children_model.php', {operation : 'get_checkedin'}, function(data){
          checked_in = data;
          var names_array = new Array();
          for (var i = 0; i < checked_in.length; i++){
            ci = checked_in[i];
            var name = ci['name'];
            names_array.push(name);            
          }
          $.post('./utilities/log_model.php', {operation : 'insert_entry', type : 'daily_log', 'names[]' : names_array});
    });
		
		setTimeout(function() {
			window.location.href = "./"
		}, 1500);
		$('#toast').toast("You just submitted the Daily Log");
	});
});
